﻿using System;

namespace HttpPublish
{
    static class Program
    {
        //public static string UserName;
        //public static string Password;

        internal static PublishConfigration Config;

        static void Main(string[] args)
        {
            try
            {

                if (args.Length >= 1)
                {
                    Config = PublishConfigration.LoadConfig(args[0]);

                    Log.Trace("Getting remote file list from {0}", Config.Host);
                    Log.Trace("Local folder {0}", Config.Local);
                    Log.Trace("Remote folder {0}", Config.Remote);
                    Console.Out.Flush();
                    var remoteTracker = new RemoteTracker(Config);
                    var remoteFiles = remoteTracker.GetFiles();

                    var localTracker = new LocalTracker(Config);
                    var localFiles = localTracker.GetFiles();

                    var publisher = new Publisher(Config, localFiles, remoteFiles);
                    publisher.Publish();
                }
                else
                {
                    Console.Write(Syntax);
                }
            }
            catch (Exception ex)
            {
                Log.Trace(ex.ToString());
            }

#if DEBUG
            // This causes console output to pause for return key for debugging
            Console.Read();
#endif
        }

        static string Syntax
        {
            get
            {
                return "Use HttpPublish HttpPublishConfigFile.json";
            }
        }
    }
}
